import json

import allure
import jsonpath
import pymysql
import requests
from deepdiff import DeepDiff


class ApiKey:

    def __init__(self):
        self.session = requests.Session()

    @allure.step(">>>>>>>>>发送get请求")
    def get(self, url, params=None, **kwargs):
        return self.session.get(url, params=params, **kwargs)

    @allure.step(">>>>>>>>>发送post请求")
    def post(self, url, params=None, data=None, json=None, **kwargs):
        return self.session.post(url, params=params, data=data, json=json, **kwargs)

    @allure.step(">>>>>>>>>发送put请求")
    def put(self, url, params=None, data=None, json=None, **kwargs):
        return self.session.put(url, params=params, data=data, json=json, **kwargs)

    @allure.step(">>>>>>>>>发送delete请求")
    def delete(self, url, params=None, **kwargs):
        return self.session.delete(url, params=params, **kwargs)


if __name__ == '__main__':
    ak = ApiKey()
    file_path = "./三十万字.jpg"
    with open(file_path, "rb") as file:
        image_data = file.read()
    print(image_data)
    print(str(image_data))
    data_dict1 = {"url": "http://127.0.0.1:8888/api/front/user/login",
                  "headers": {"Content-Type": "application/json;charset=UTF-8"},
                  "json": {"username": "18855688009", "password": "xx958012725"}}
    data_dict = {"url": "http://127.0.0.1:8888/api/front/resource/image", "headers":{"authorization": "eyJzeXN0ZW1LZXlIZWFkZXIiOiJmcm9udCIsImFsZyI6IkhTMjU2In0.eyJzdWIiOiIxIn0.bjqJ6Rp6PzZ0Y9Sjk53ITn2y-O6eilxNmcKtb2CKrg0"}, "json": {"file": str(image_data)}}
    res = getattr(ak, "post")(**data_dict)
    print(res.json())
